var res [][]int
var used map[int]bool
func subsetsWithDup(nums []int) [][]int {
    res = make([][]int, 0)
    used = make(map[int]bool, 0)
    sort.Ints(nums)
    backTracking(nums, 0, []int{})
    return res
}

func backTracking(nums []int, startIndex int, path []int){
    tem := make([]int, len(path))
    copy(tem, path)
    res = append(res, tem)
    for i:=startIndex; i<len(nums); i++ {
        if i>0 && nums[i] == nums[i-1] && used[i-1] == false{
            continue
        }
        path = append(path, nums[i])
        used[i] = true
        backTracking(nums, i+1, path)
        used[i] = false
        path = path[:len(path)-1]
    }
}